package main

import (
	"encoding/json"
	"fmt"
	"github.com/valyala/fasthttp"
	"net/http"
)

func jsonPost(){
	url := `http://127.0.0.1:8080/post/json`

	req := &fasthttp.Request{} //相当于获取一个对象

	req.SetRequestURI(url) //设置请求的url
	data := map[string]interface{}{"abc": 123}
	bytes, err := json.Marshal(data) //data是请求数据
	if err != nil {
		return
	}

	req.SetBody(bytes) //存储转换好的数据

	req.Header.SetContentType("application/json") //设置header头信息

	req.Header.SetMethod(http.MethodPost) //设置请求方法

	resp := &fasthttp.Response{} //相应结果的对象

	client := &fasthttp.Client{} //发起请求的对象

	if err := client.Do(req, resp); err != nil {
		fmt.Println(err,"123123123123")
		return
	}

	fmt.Println(string(resp.Body()))
}
